@{
    ViewData["Title"] = "林场管理系统";
}

@model WebApplication11.Models.message

@if (ViewBag.Status == 1)
    {<div class="jumbotron">
         <div class="panel panel-default">
             <div class="panel-heading">
                         <h3 class="panel-title">
                             <p>欢迎 @if (ViewBag.Identity != 0)
                                   {
                                       <a> @ViewBag.Identity 个林区的管理员 </a>
                                   } @ViewBag.username</p>
                         </h3>
                     </div>
             @using (Html.BeginForm("showMine", "admin"))
             {
                 <div style="text-align: center">
                     <input class="btn btn-primary" type="submit" value="仅看自己"/>
                     @* 使用onclick更改action从而访问不同后端接口 *@
                     <input class="btn btn-primary col-sm-offset-1" type="submit" value="查看全部"
                            onclick="this.form.action='admin/showAll'"/>
                     <input class="btn btn-primary col-sm-offset-1" type="submit" value="插入信息"
                            onclick="this.form.action='admin/insertNewAssets'"/>
                     
                 </div>
             }
             <div style="float: right">
                 <form action="~/admin/Search" method="post">
                     <input name="msg"/>
                     <input type="submit" class="btn btn-primary"/>
                 </form>
             </div>
             <div class="panel-body">
                 <table class="table table-striped" style="table-layout: fixed">
                     <thead>
                     <tr>
                         <th>护林员</th>
                         <th>名称</th>
                         <th>数目</th>
                         <th>操作</th>
                     </tr>
                     </thead>
                     <tbody>
                     @foreach (var item in (List<message>)ViewBag.assetss)
                     {
                         <form action="~/admin/Updateassets" method="post">
                             <tr>
                                 <td hidden="hidden">
                                     <input name="Id" value="@item.Id" class = "form-control"/>
                                 </td>
                                 <td style="width: 95%">
                                     <input name="Leader" value="@item.Leader" readonly="readonly" class = "form-control"/>
                                 </td>
                                 <td style="width: 95%">
                                     <input name="Name" value="@item.Name" readonly="readonly" class = "form-control"/>
                                 </td>
                                 <td style="width: 95%;" contenteditable="true">
                                     <input name="Num" value="@item.Num" class = "form-control"/>
                                 </td>
                                 <td>
                                     <div class="btn-group btn-group-sm">
                                         <input class="btn btn-primary" type="submit" value="修改"/>
                                         <input class="btn btn-primary" type="button" value="删除" onclick="del(@item.Id)"/>
                                     </div>
                                 </td>
                             </tr>
                         </form>
                         <script>
                         function del(id) {
                                 $.ajax({
                                     url: "admin/Deleteassets",
                                     type:"post",
                                     data: {
                                       "id" : id
                                     },
                                     dataType: "json",
                                     success: function() {
                                         alert("删除成功");
                                         location.reload();
                                     }
                                 });
                         }
                         </script>
                     }
                     @if (ViewBag.Insert != 0)
                     {
                         <form action="~/admin/addNew" method="post">
                             <tr>
                                 <td hidden="hidden">
                                     <input name="Id" value="@ViewBag._max" class = "form-control"/>
                                 </td>
                                 <td>
                                     <input name="Leader" value="" class = "form-control"/>
                                 </td>
                                 <td>
                                     <input name="Name" value="" class = "form-control"/>
                                 </td>
                                 <td>
                                     <input name="Num" value="" class = "form-control"/>
                                 </td>
                                 <td>
                                     <div class="btn-group btn-group-sm">
                                         <input class="btn btn-primary col-sm-offset-1" type="submit" value="插入"/>
                                     </div>
                                 </td>
                             </tr>
                         </form>
                     }
                     </tbody>
                 </table>
             </div>
         </div>
     </div>
    }
else
{
    <p>请先登录</p>
}